home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / inchstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.8 KB  |  228 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    inchstr
  24. #undef    inchnstr
  25. #undef    winchstr
  26. #undef    winchnstr
  27. #undef    mvinchstr
  28. #undef    mvinchnstr
  29. #undef    mvwinchstr
  30. #undef    mvwinchnstr
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    move
  35. #  undef    wmove
  36. #endif
  37.  
  38. #ifdef PDCDEBUG
  39. char *rcsid_inchstr  = "$Id$";
  40. #endif
  41.  
  42. /*man-start*********************************************************************
  43.  
  44.   Name:                                                        inchstr
  45.  
  46.   Synopsis:
  47.       int inchstr(chtype *ch);
  48.       int inchnstr(chtype *ch, int n);
  49.       int winchstr(WINDOW *win, chtype *ch);
  50.       int winchnstr(WINDOW *win, chtype *ch, int n);
  51.       int mvinchstr(int y, int x, chtype *ch);
  52.       int mvinchnstr(int y, int x, chtype *ch, int n);
  53.       int mvwinchstr(WINDOW *, int y, int x, chtype *ch);
  54.       int mvwinchnstr(WINDOW *, int y, int x, chtype *ch, int n);
  55.  
  56.   X/Open Description:
  57.      These routines read a chtype string directly from the window structure
  58.      starting at the current position and ending at the right margin.
  59.      The four routines with n as the last argument copy at most n
  60.      elements, but no more than will fit on the line.
  61.  
  62.      NOTE:    inchstr(), mvinchstr(), mvwinchstr() inchnstr(), 
  63.          mvinchnstr(), and mvwinchnstr() are implemented as macros.
  64.  
  65.   X/Open Return Value:
  66.      All functions return ERR on error and an integer value other than
  67.      ERR on success. 
  68.  
  69.   X/Open Errors:
  70.      Normally the value returned indicates the number of chtypes
  71.      returned.
  72.  
  73.   Portability                             X/Open    BSD    SYS V
  74.                                           Dec '88
  75.       inchstr                               -        -      4.0
  76.       winchstr                              -        -      4.0
  77.       mvinchstr                             -        -      4.0
  78.       mvwinchstr                            -        -      4.0
  79.       inchnstr                              -        -      4.0
  80.       winchnstr                             -        -      4.0
  81.       mvinchnstr                            -        -      4.0
  82.       mvwinchnstr                           -        -      4.0
  83.  
  84. **man-end**********************************************************************/
  85.  
  86. /***********************************************************************/
  87. int    inchstr(chtype *ch)
  88. /***********************************************************************/
  89. {
  90.     int i;
  91. #ifdef PDCDEBUG
  92.     if (trace_on) PDC_debug("inchstr() - called\n");
  93. #endif
  94.  
  95.     if (stdscr == (WINDOW *)NULL)
  96.         return( ERR );
  97.  
  98.     return( inchnstr( ch, stdscr->_maxx - stdscr->_curx ) );
  99. }
  100. /***********************************************************************/
  101. int    inchnstr(chtype *ch, int n)
  102. /***********************************************************************/
  103. {
  104.     chtype    *ptr = &(stdscr->_y[stdscr->_cury][stdscr->_curx]);
  105.     int    i;
  106. #ifdef PDCDEBUG
  107.     if (trace_on) PDC_debug("inchnstr() - called\n");
  108. #endif
  109.  
  110.     if (stdscr == (WINDOW *)NULL)
  111.         return( ERR );
  112.  
  113.     if (n < 0)
  114.         return( ERR );
  115.  
  116.     if ((stdscr->_curx + n) > stdscr->_maxx)
  117.         n = stdscr->_maxx - stdscr->_curx;
  118.  
  119.     for(i=0;i<n;i++)
  120.         *ch++ = *ptr++;
  121.  
  122.     *ch = (chtype)0;
  123.     return(i);
  124. }
  125. /***********************************************************************/
  126. int    winchstr(WINDOW *win, chtype *ch)
  127. /***********************************************************************/
  128. {
  129. #ifdef PDCDEBUG
  130.     if (trace_on) PDC_debug("winchstr() - called\n");
  131. #endif
  132.  
  133.     if (win == (WINDOW *)NULL)
  134.         return( ERR );
  135.  
  136.     return(winchnstr(win,ch,win->_maxx - win->_curx));
  137. }
  138. /***********************************************************************/
  139. int    winchnstr(WINDOW *win, chtype *ch, int n)
  140. /***********************************************************************/
  141. {
  142.     chtype    *ptr = &(win->_y[win->_cury][win->_curx]);
  143.     int    i;
  144. #ifdef PDCDEBUG
  145.     if (trace_on) PDC_debug("winchnstr() - called\n");
  146. #endif
  147.  
  148.     if (win == (WINDOW *)NULL)
  149.         return( ERR );
  150.  
  151.     if (n < 0)
  152.         return( ERR );
  153.  
  154.     if ((win->_curx + n) > win->_maxx)
  155.         n = win->_maxx - win->_curx;
  156.  
  157.     for(i=0;i<n;i++)
  158.         *ch++ = *ptr++;
  159.  
  160.     *ch = (chtype)0;
  161.     return(i);
  162. }
  163. /***********************************************************************/
  164. int    mvinchstr(int y, int x, chtype *ch)
  165. /***********************************************************************/
  166. {
  167. #ifdef PDCDEBUG
  168.     if (trace_on) PDC_debug("mvinchstr() - called: y %d x %d\n",y,x);
  169. #endif
  170.  
  171.     if (stdscr == (WINDOW *)NULL)
  172.         return( ERR );
  173.  
  174.     if (wmove(stdscr,y,x) == ERR)
  175.         return( ERR );
  176.  
  177.     return( inchnstr( ch, stdscr->_maxx - stdscr->_curx) );
  178. }
  179. /***********************************************************************/
  180. int    mvinchnstr(int y, int x, chtype *ch, int n)
  181. /***********************************************************************/
  182. {
  183. #ifdef PDCDEBUG
  184.     if (trace_on) PDC_debug("mvinchnstr() - called: y %d x %d n %d\n",y,x,n);
  185. #endif
  186.  
  187.     if (stdscr == (WINDOW *)NULL)
  188.         return( ERR );
  189.  
  190.     if (wmove(stdscr,y,x) == ERR)
  191.         return( ERR );
  192.  
  193.     return( inchnstr( ch, n) );
  194. }
  195. /***********************************************************************/
  196. int    mvwinchstr(WINDOW *win, int y, int x, chtype *ch)
  197. /***********************************************************************/
  198. {
  199. #ifdef PDCDEBUG
  200.     if (trace_on) PDC_debug("winchstr() - called:\n");
  201. #endif
  202.  
  203.     if (win == (WINDOW *)NULL)
  204.         return( ERR );
  205.  
  206.     if (wmove(win,y,x) == ERR)
  207.         return( ERR );
  208.  
  209.     return( winchnstr( win, ch, win->_maxx - win->_curx) );
  210. }
  211. /***********************************************************************/
  212. int    mvwinchnstr(WINDOW *win,int y, int x, chtype *ch, int n)
  213. /***********************************************************************/
  214. {
  215. #ifdef PDCDEBUG
  216.     if (trace_on) PDC_debug("mvwinchnstr() - called: y %d x %d n %d \n",y,x,n);
  217. #endif
  218.  
  219.     if (win == (WINDOW *)NULL)
  220.         return( ERR );
  221.  
  222.     if (wmove(win,y,x) == ERR)
  223.         return( ERR );
  224.  
  225.     return( winchnstr( win, ch, n) );
  226. }
  227.